package com.web.controller;

import com.web.beans.DictionaryType;
import com.web.dto.ResultDTO;
import com.web.exteption.MyException;
import com.web.services.DictionaryTypeServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;

@RestController
@RequestMapping("/DictionaryType")
public class DictionaryTypeController {

    @Autowired
    DictionaryTypeServices dictionaryTypeServices;

    @RequestMapping("getAll.action")
    public ResultDTO getAll(){
        ResultDTO resultDTO = new ResultDTO();
        ArrayList<DictionaryType> all = dictionaryTypeServices.getAll();
        resultDTO.setResult(true);
        resultDTO.setMess("查询成功");
        resultDTO.setData(all);

        return resultDTO;
    }

    @RequestMapping("del.action")
    public ResultDTO del(String id) throws MyException {
        ResultDTO resultDTO = new ResultDTO();
        dictionaryTypeServices.del(id);
        resultDTO.setResult(true);
        resultDTO.setMess("删除成功");
        resultDTO.setData(null);

        return resultDTO;
    }

    @RequestMapping("add.action")
    public ResultDTO add(DictionaryType dictionaryType) throws MyException {
        ResultDTO resultDTO = new ResultDTO();
        dictionaryTypeServices.add(dictionaryType);
        resultDTO.setResult(true);
        resultDTO.setMess("添加成功");
        resultDTO.setData(null);

        return resultDTO;
    }

    @RequestMapping(value = "editBefore.action")
    public ResultDTO get(String  id) throws MyException {
        ResultDTO resultDTO=new ResultDTO();
        DictionaryType dictionaryType = dictionaryTypeServices.get(id);
        resultDTO.setResult(true);
        resultDTO.setMess("按照ID查询成功");
        resultDTO.setData(dictionaryType);
        return resultDTO;
    }

    @RequestMapping(value = "edit.action")
    public ResultDTO edit(DictionaryType dictionaryType) throws MyException {
        ResultDTO resultDTO=new ResultDTO();
        dictionaryTypeServices.edit(dictionaryType);
        resultDTO.setResult(true);
        resultDTO.setMess("修改成功");
        resultDTO.setData(null);
        return resultDTO;
    }
}
